<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商品')" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-goods-add">
        <div class="form-group">
            <label class="col-sm-3 control-label">商品名称：</label>
            <div class="col-sm-8">
                <input name="goodsName" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">商品地址：</label>
            <div class="col-sm-8">
                <input type="hidden" name="goodsUrl">
                <div class="file-loading">
                    <input class="form-control file-upload" id="goodsUrl" name="file" type="file">
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">金额：</label>
            <div class="col-sm-8">
                <input name="money" class="form-control" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">是否可用：</label>
            <div class="col-sm-8">
                <select name="state" class="form-control m-b" th:with="type=${@dict.getType('rest_state')}">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: bootstrap-fileinput-js"/>
<script th:inline="javascript">
    var prefix = ctx + "rest/goods"
    $("#form-goods-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-goods-add').serialize());
        }
    }

    $(".file-upload").fileinput({
        uploadUrl: ctx + 'common/upload',
        maxFileCount: 1,
        autoReplace: true
    }).on('fileuploaded', function (event, data, previewId, index) {
        console.log("上传成功");
        $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
    }).on('fileremoved', function (event, id, index) {
        console.log("上传失败");
        $("input[name='" + event.currentTarget.id + "']").val('')
    })
</script>
</body>
</html>